package com.semidata.rtd.core.executor;

import java.util.HashMap;
import java.util.Map;

import com.semidata.rtd.core.service.Service;

public class TaskExecutorService implements Service {
    
    private Map<Class<? extends TaskExecutor>, TaskExecutor> map = new HashMap<>();
    
    public TaskExecutorService(TaskExecutor ... executors) {
        
        for (TaskExecutor executor : executors) {
            register(executor);
        }
        
    }
    
    public void register(TaskExecutor executor) {
        map.put(executor.getClass(), executor);
    }

    @Override
    public void start() {
        for (TaskExecutor executor : map.values()) {
            executor.start();
        }
        
    }

    @Override
    public void stop() {
        for (TaskExecutor executor : map.values()) {
            executor.stop();
        }        
    }
    
    public TaskExecutor getTaskExecutor(Class<? extends TaskExecutor> name) {
        return map.get(name);
    }

}
